package com.xxx.springboot.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 发送短信服务
 */
@Service
public class SendMessageService {
	
	Logger log = LoggerFactory.getLogger(SendMessageService.class);
	
	// 发送短信提醒1
	@Async("taskExecutor")  // 对应configuration里的线程池taskExecutor
	// 加与不加@Async的区别：加上@Async时，多个线程是为异步并发；否则为同步执行
	public void sendMessage1() throws InterruptedException {
		log.info("发送短信提醒1----1	执行开始. currentTime:"+System.currentTimeMillis());
		Thread.sleep(5000); // 模拟调用第三方短信服务接口耗时
		log.info("发送短信提醒1----1 	执行结束. currentTime:"+System.currentTimeMillis());
	}
	
	// 发送短信提醒2
	@Async("taskExecutor")  // 加与不加@Async的区别：加上@Async时，多个线程是为异步并发；否则为同步执行
	public void sendMessage2() throws InterruptedException {
		log.info("发送短信提醒2----2	执行开始. currentTime:"+System.currentTimeMillis());
		Thread.sleep(3000); // 模拟调用第三方短信服务接口耗时
		log.info("发送短信提醒2----2 	执行结束. currentTime:"+System.currentTimeMillis());
	}

}
